package cn.lili.modules.grab.alibaba.serviceimpl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.modules.file.client.UploadClient;
import cn.lili.modules.file.util.FileUtil;
import cn.lili.modules.goods.client.GoodsClient;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dos.GoodsGallery;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
import cn.lili.modules.goods.entity.enums.*;
import cn.lili.modules.goods.integration.GoodsIntegrationService;
import cn.lili.modules.grab.alibaba.constant.GlobalTools;
import cn.lili.modules.grab.alibaba.mapper.GoodsGrabMapper;
import cn.lili.modules.grab.alibaba.service.GoodsGrabUpdateService;
import cn.lili.modules.grab.entity.dos.GoodsGrab;
import cn.lili.modules.grab.entity.dto.alibaba.*;
import cn.lili.modules.grab.entity.vos.CollectGoodsData;
import cn.lili.modules.system.client.SettingClient;
import cn.lili.modules.system.entity.dos.Setting;
import cn.lili.modules.system.entity.dto.GoodsSetting;
import cn.lili.modules.system.entity.enums.SettingEnum;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jodd.util.StringUtil;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class GoodsGrabUpdateServiceImpl extends ServiceImpl<GoodsGrabMapper, GoodsGrab>
        implements GoodsGrabUpdateService {

    @Autowired
    private GoodsClient goodsClient;

    @Autowired
    private GoodsIntegrationService goodsIntegrationService;

    @Autowired
    private UploadClient uploadClient;


    @Autowired
    private SettingClient settingClient;


    public void updateGoodsGrab(String grabId, Integer status) {
        GoodsGrab grab = this.getById(grabId);
        if (null != grab) {

            int $total_num = grab.getTotalNum() + 1;
            int $success_num = grab.getSuccessNum();
            int $error_num = grab.getErrorNum();

            if (status == 1) {
                $success_num += 1;
            } else {
                $error_num += 1;
            }
            grab.setErrorNum($error_num);
            grab.setSuccessNum($success_num);
            grab.setTotalNum($total_num);

            this.updateById(grab);
        }
    }

    @Override
    public GoodsOperationDTO getGoodsOperationDTO(String url) {
        try {
            if(StringUtil.isEmpty(url)){
                return null;
            }
           GoodsOperationDTO goodsOperationDTO = new GoodsOperationDTO();
            //判断链接合法性
            if (!GlobalTools.is_url(url)) {
                throw new ServiceException("url地址不正确");
            }
            //判断url类型  及 获取id
            URL urlObj = null;
            urlObj = new URL(url);
            String host = urlObj.getHost();
            Map<String, String> typeMap = GlobalTools.getUrlType(host);
            String id = "";
            String grabType = typeMap.get("type");
            if (grabType.equals("jd") || grabType.equals("1688")) {
                String path = urlObj.getPath();
                Pattern p = Pattern.compile("[^0-9]");
                Matcher m = p.matcher(path);
                id = m.replaceAll("").trim();
            } else {
                Map<String, Object> queryMap = GlobalTools.convertUrlQuery(urlObj.getQuery());
                if (null != queryMap && queryMap.containsKey("id")) {
                    id = (String) queryMap.get("id");
                }
            }

            String api99Key = "86A3EEBE94E87596628E910E0CE7B0CA";
            String request_url = GlobalTools.getCollectUrl(grabType);
            Map<String, String> param = new LinkedHashMap<>();
            param.put("apikey", api99Key);
            param.put("itemid", id);

            String result = HttpUtil.get(request_url + "?apikey=" + api99Key + "&itemid=" + id);

            log.debug("==============grab result ==>" + result);
            AlibabaGoodsGrabRespParam respParam = null;
            try {
                respParam = JSON.parseObject(result, AlibabaGoodsGrabRespParam.class);
            }catch (Exception e){
                e.printStackTrace();
                return null;
            }

            if (!respParam.getRetcode().equals("0000")) {
                return null;
            }

            CollectGoodsData collectGoodsData = new CollectGoodsData();
            switch (grabType) {
                case "taobao":
                    collectGoodsData = taobaoHandleData(null, null);
                    break;
                case "tmall":
                    collectGoodsData = tmallHandleData(null, null);
                    break;
                case "jd":
                    collectGoodsData = jdHandleData(null, null);
                    break;
                case "1688":
                    collectGoodsData = alibabaHandleData(respParam, null);
                    break;
            }


            if (null == collectGoodsData || StringUtil.isEmpty(collectGoodsData.getGoods_name())) {
               return null;
            }

            Map<String, GoodsSpec> goodsSpecMap = collectGoodsData.getSkuMap();
            if (null == goodsSpecMap || goodsSpecMap.isEmpty()) {
               return null;
            }
            String goodsPrice = collectGoodsData.getPrice();
            if (StringUtil.isEmpty(goodsPrice)) {
                return null;
            }

            goodsOperationDTO.setGoodsName(collectGoodsData.getGoods_name());
            goodsOperationDTO.setGoodsUnit(collectGoodsData.getUnit());
            goodsOperationDTO.setRelease(false);
            //goodsOperationDTO.setPr(PurchaseRuleEnum.SKU);
            goodsOperationDTO.setPrice(Double.parseDouble(collectGoodsData.getPrice()));
            goodsOperationDTO.setIntro(collectGoodsData.getGoods_content());
            goodsOperationDTO.setGoodsFrom(2);
            goodsOperationDTO.setGoodsGrabUrl(url);
            goodsOperationDTO.setSalesModel(SalesModeEnum.RETAIL.name());
            goodsOperationDTO.setGoodsGalleryList(collectGoodsData.getImageList());
            goodsOperationDTO.setGoodsType(GoodsTypeEnum.PHYSICAL_GOODS.name());
            //goodsOperationDTO(true); //支持代发
            //goodsOperationDTO.setSupportPurchase(false); //不支持采购
            goodsOperationDTO.setThirdPartId("010101010");
            goodsOperationDTO.setMarketEnable(GoodsMarketEnum.UPPER.name());
            goodsOperationDTO.setAuthFlag(GoodsAuthEnum.PASS.name());
            List<SkuProps> skuPropsList = collectGoodsData.getSkuPropsList();
            SkuProps existImageProps = null;


            List<Map<String, Object>> skuMapList = new ArrayList<>();

            //查找包含图片的sku
            for (SkuProps one : skuPropsList) {
                List<SkuValue> skuValues = one.getValue();
                if (skuValues.stream().anyMatch(v -> StringUtil.isNotEmpty(v.getImageUrl()))) {
                    existImageProps = one;
                    break;
                }
            }
            //商品的sku列表没有包含图片的数据，则取一个sku的数据，并填充相册中的第一张图片
            if (null == existImageProps) {
                String skuImg = collectGoodsData.getImageList().get(0);//取相册中的第一条记录作为sku的图片
                SkuProps defaultOne = skuPropsList.get(0);
                List<SkuValue> skuValues = defaultOne.getValue();
                skuValues.forEach(e -> e.setImageUrl(skuImg));
                existImageProps = defaultOne;
            }

            if (null != existImageProps) {
                List<SkuValue> skuValues = existImageProps.getValue();
                for (SkuValue v : skuValues) {
                    Map<String, Object> skuItem = new LinkedHashMap<>();
                    skuItem.put(GoodsSku.IMAGES_KEY, v.getImageUrl());
                    skuItem.put("specName", v.getName());
                    Map<String, Object> specJson = new LinkedHashMap<>();
                    specJson.put(existImageProps.getProp(), v.getName());
                    skuItem.put("specJson", JSON.toJSONString(specJson));
                    skuMapList.add(skuItem);
                }

                SkuProps existImageProps1 = existImageProps;
                List<SkuProps> leftSkuPropsList = skuPropsList.stream().filter(item -> !item.getFid().equals(existImageProps1.getFid())).collect(Collectors.toList());
                if (null != leftSkuPropsList && !leftSkuPropsList.isEmpty()) {
                    for (SkuProps one : leftSkuPropsList) {
                        List<SkuValue> skuValues1 = one.getValue();
                        List<Map<String, Object>> skuMapTemp = new ArrayList<>();
                        for (SkuValue skuv : skuValues1) {
                            for (Map map : skuMapList) {
                                Map<String, Object> skuItem = new LinkedHashMap<>();
                                String specName = (String) map.get("specName") + " " + skuv.getName();
                                skuItem.put(GoodsSku.IMAGES_KEY, (String) map.get(GoodsSku.IMAGES_KEY));
                                skuItem.put("specName", specName);
                                Map<String, Object> specJson = JSON.parseObject((String) map.get("specJson"));
                                specJson.put(one.getProp(), skuv.getName());
                                skuItem.put("specJson", JSON.toJSONString(specJson));
                                skuMapTemp.add(skuItem);
                            }
                        }
                        skuMapList = skuMapTemp;
                    }
                }
            }

            List<Map<String, Object>> skuMapList1 = skuMapList;
            log.debug("=====skuMapList>>>>" + JSON.toJSONString(skuMapList));
            //商品的sku数据
            List<Map<String, Object>> skuList = new ArrayList<>();


            /**
             * 将sku数据按规格组合顺序回填相关字段
             */
            List<String> specKeyList = goodsSpecMap.keySet().stream().toList();
            for (Map<String, Object> existMap : skuMapList1) {
                GoodsSpec goodsSpec = null;
                String name = (String) existMap.get("specName");
                for(String specName : specKeyList){
                    String specName1 = specName.replace("&gt;", " ");
                    if (specName1.contains(name)) {
                        goodsSpec = goodsSpecMap.get(specName);
                        break;
                    }
                }
                if (null != goodsSpec) {
                    Map<String, Object> objectMap = new LinkedHashMap<>();
                    String skuPrice = goodsPrice;
                    if (null != goodsSpec.getDiscountPrice() && !"".equals(goodsSpec.getDiscountPrice())) {
                        objectMap.put(GoodsSku.COST_KEY, goodsSpec.getDiscountPrice());
                        skuPrice = goodsSpec.getDiscountPrice();
                    } else {
                        objectMap.put(GoodsSku.COST_KEY, goodsPrice);
                    }
                    objectMap.put(GoodsSku.SN_KEY, goodsSpec.getSkuId());
                    objectMap.put(GoodsSku.PRICE_KEY, skuPrice); //默认的sku价格，
                    objectMap.put(GoodsSku.QUANTITY_KEY, goodsSpec.getCanBookCount());
                    objectMap.put(GoodsSku.WEIGHT_KEY, 1);
                    String skuImage = (String) existMap.get(GoodsSku.IMAGES_KEY);
                    if (StringUtil.isNotEmpty(skuImage)) {
                        //skuImage = uploadImage(skuImage);
                        Map<String, String> imageMap = new LinkedHashMap<>();
                        imageMap.put("url", skuImage);
                        List<Map<String, String>> imageList = new ArrayList<>();
                        imageList.add(imageMap);
                        objectMap.put(GoodsSku.IMAGES_KEY, imageList);
                    }
                    Map<String, Object> specJson = JSON.parseObject((String) existMap.get("specJson"), LinkedHashMap.class);
                    specJson.forEach((kk, vv) -> {
                        objectMap.put(kk, vv);
                    });
                    skuList.add(objectMap);
                }
            }

            goodsOperationDTO.setSkuList(skuList);


            log.debug("=====采集商品入库数据>>>>" + JSON.toJSONString(goodsOperationDTO));
            return goodsOperationDTO;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("定时采集失败{}" + e.getMessage());
            return null;
        }
    }

    /**
     * 淘宝数据处理
     */
    public CollectGoodsData taobaoHandleData(JSONObject $params, String $site_id) {
        return new CollectGoodsData();
    }

    /**
     * 天猫数据处理
     */
    public CollectGoodsData tmallHandleData(JSONObject $params, String $site_id) {
        return new CollectGoodsData();
    }

    /**
     * 京东数据处理
     */
    public CollectGoodsData jdHandleData(JSONObject $params, String $site_id) {
        return new CollectGoodsData();
    }

    /**
     * 1688数据处理
     */
    public CollectGoodsData alibabaHandleData(AlibabaGoodsGrabRespParam respParam, String $site_id) {
        Random random = new Random();
        CollectGoodsData data = new CollectGoodsData();
        try {
            GoodsDetail goodsDetail = respParam.getData();
            if (null != goodsDetail) {
                data.setGoods_name(goodsDetail.getTitle()); //名称
                data.setUnit(goodsDetail.getUnit()); //单位
                data.setSite_id($site_id); //供应商ID
                data.setVideo_url(goodsDetail.getVideoUrl());
                if (!goodsDetail.getSkuProps().isEmpty()) {
                    for (int i = 0, len = goodsDetail.getSkuProps().size(); i < len; i++) {
                        SkuProps skuProps = goodsDetail.getSkuProps().get(i);
                        String specId = (i + 1) + "" + random.nextInt(1, 99) + "" + random.nextInt(1, 999);
                        skuProps.setSpecId(specId);
                        for (int j = 0, len1 = skuProps.getValue().size(); j < len1; j++) {
                            String specValueId = (j + 1) + "" + random.nextInt(1, 999) + "" + random.nextInt(1, 99);
                            SkuValue skuValue = skuProps.getValue().get(j);
                            skuValue.setSpec_id(specId);
                            skuValue.setSpec_name(skuProps.getSpecName());
                            skuValue.setSpec_value_id(specValueId);
                            skuProps.getValue().set(j, skuValue);
                        }
                        goodsDetail.getSkuProps().set(i, skuProps);
                    }
                }

                String[] $priceArray = goodsDetail.getDisplayPrice().split("-");
                String price = $priceArray[0].replace("￥", "");
                data.setPrice(price);

                //组合商品sku
                Map<String, GoodsSpec> skuMap = goodsDetail.getSkuMap();
                data.setSkuMap(skuMap);
                data.setSkuPropsList(goodsDetail.getSkuProps());
                data.setGoods_content(goodsDetail.getDesc());
                List<String> imgList = new ArrayList<>();
//                goodsDetail.getImages().forEach(item->{
//                    String result = uploadImage(item);
//                    if(null!=result){
//                        imgList.add(result);
//                    }
//                });
                imgList = goodsDetail.getImages();
                data.setImageList(imgList);

                //详情图片转换
                //               List<String> descImgList = new ArrayList<>();
//                goodsDetail.getDescImgs().forEach(item->{
//                    String result = uploadImage(item);
//                    if(null!=result){
//                        descImgList.add(result);
//                    }
//                });
                StringBuilder descContent = new StringBuilder();
                descContent.append("<p>");
                goodsDetail.getDescImgs().forEach(item -> {
                    descContent.append("<img src=\"" + item + "\" />");
                });
                descContent.append("</p>");
                data.setGoods_content(descContent.toString());

                //data.setGoods_content(goodsDetail.getDesc());
            }
            return data;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public String uploadImage(String imgUrl) {
        return uploadClient.upload(imgUrl);
    }


    @SneakyThrows
    @Override
    public String isDown(Goods goods) {
        try {
            String storeId = goods.getStoreId();
            if (null == goods) {
                return "商品不存在";
            }
            //采集过来的数据
            GoodsOperationDTO goodsOperationDTO = getGoodsOperationDTO(goods.getGoodsGrabUrl());
            if (null == goodsOperationDTO) {
//                GoodsOperationDTO operationDTO = new GoodsOperationDTO();
//                operationDTO.setGoodsId(goods.getId());
//                operationDTO.setMarketEnable(GoodsMarketEnum.DOWN.name());
//                this.goodsIntegrationService.updateGoods(operationDTO);
            } else {
                List<Map<String, Object>> grabSkus = goodsOperationDTO.getSkuList();
                for (Map<String, Object> skuMap : grabSkus) {
                    String costStr = String.valueOf(skuMap.get(GoodsSku.COST_KEY));
                    BigDecimal cost = new BigDecimal(costStr); //成本价
                    BigDecimal price = cost.add(cost.multiply(new BigDecimal(0.1))).setScale(1, RoundingMode.HALF_UP);
                    Integer greenScore = price.add(price.multiply(new BigDecimal(0.2))).setScale(0, RoundingMode.CEILING).intValue();
                    skuMap.put(GoodsSku.GREEN_SCORE, greenScore);
                    skuMap.put(GoodsSku.PRICE_KEY, price);
                }
                goodsOperationDTO.setSkuList(grabSkus);
                goodsOperationDTO.setStoreId(storeId);
                goodsOperationDTO.setScene(SceneEnums.STORE.name());
                goodsOperationDTO.setStoreName("飞语专供");
                goodsOperationDTO.setField5("fy666666");
                goodsOperationDTO.setField4(goods.getId());
                goodsOperationDTO.setCategoryPath(goods.getCategoryPath());
                goodsOperationDTO.setRegeneratorSkuFlag(true);
                this.goodsIntegrationService.saveGoods(goodsOperationDTO);
            }

        }catch (Exception e){
            e.printStackTrace();
        }

        return "success";
    }

    @Override
    public void transferImageToOss(Goods goods) {
        String keystr = "https://feiyu-lshop";
        List<GoodsGallery> galleryList = goodsClient.getGoodsGallery(goods.getId());
        List<GoodsGallery> updateList = new ArrayList<>();
        if(null!=galleryList && galleryList.size()>0){
            galleryList.forEach(item->{
                if(item.getOriginal().startsWith(keystr)){

                }else{
                    String oriPath = item.getOriginal();
                    String ossPath = uploadClient.upload(oriPath);
                    if(null!=ossPath){
                        Setting setting = settingClient.get(SettingEnum.GOODS_SETTING.name());
                        GoodsSetting goodsSetting = JSONUtil.toBean(setting.getSettingValue(), GoodsSetting.class);
                        //缩略图
                        String thumbnail = FileUtil.getUrl(ossPath, goodsSetting.getAbbreviationPictureWidth(), goodsSetting.getAbbreviationPictureHeight());
                        //小图
                        String small = FileUtil.getUrl(ossPath, goodsSetting.getSmallPictureWidth(), goodsSetting.getSmallPictureHeight());
                        //赋值
                        item.setSmall(small);
                        item.setThumbnail(thumbnail);
                        item.setOriginal(ossPath);

                        updateList.add(item);
                    }
                }
            });
            if(updateList.size()>0){
                goodsClient.updateGoodsGallery(updateList);
            }
        }
        //处理详情图片转换
        if(StringUtil.isNotEmpty(goods.getIntro())){
            if(!goods.getIntro().contains(keystr)){
                List<String> imgList = getUrls(goods.getIntro());
                System.out.println("==================imgList size ==" + imgList);
                StringBuilder descContent = new StringBuilder();
                descContent.append("<p>");
                imgList.forEach(item-> {
                    System.out.println("==================图片详情转换0 ==" + item);
                    String ossPath = uploadClient.upload(item);
                    System.out.println("==================图片详情转换1 ==" + ossPath);
                    if(null!=ossPath){
                        descContent.append("<img src=\""+ossPath+"\" />");
                    }
                });
                descContent.append("</p>");
                goods.setIntro(descContent.toString());
                goods.setOriginal(galleryList.get(0).getOriginal());
                goods.setThumbnail(galleryList.get(0).getThumbnail());
                goods.setSmall(galleryList.get(0).getSmall());
                goodsClient.updateGoodsInfoImages(goods);
            }


//            List<String> imgList = getUrls(goods.getIntro());
//            System.out.println("==================imgList size ==" + imgList);
//            StringBuilder descContent = new StringBuilder();
//            descContent.append("<p>");
//            imgList.forEach(item-> {
//                System.out.println("==================图片详情转换0 ==" + item);
//                String ossPath = uploadClient.upload(item);
//                System.out.println("==================图片详情转换1 ==" + ossPath);
//                if(null!=ossPath){
//                    descContent.append("<img src=\""+ossPath+"\" />");
//                }
//            });

        }

        //处理sku图片的转换
        GoodsSearchParams searchParams = new GoodsSearchParams();
        searchParams.setGoodsId(goods.getId());
        List<GoodsSku> skuList = goodsClient.getGoodsSkuByList(searchParams);
        List<GoodsSku> skuUpdateList = new ArrayList<>();
        if(null!=skuList && skuList.size()>0){
            skuList.forEach(item->{
                Map<String,Object> specMap  = JSON.parseObject(item.getSpecs(),Map.class);
                if(specMap.containsKey(GoodsSku.IMAGES_KEY)){
                    List<Map<String,String>> imgList = (List<Map<String, String>>)specMap.get(GoodsSku.IMAGES_KEY);
                    if(!imgList.isEmpty()){
                        Map<String,String> mm = imgList.get(0);
                        String url = mm.get("url");
                        if(!url.contains(keystr)){
                            String ossPath = uploadClient.upload(url);
                            System.out.println("================sku ori="+url+",to="+ossPath);
                            if(null!=ossPath){
                                Setting setting = settingClient.get(SettingEnum.GOODS_SETTING.name());
                                GoodsSetting goodsSetting = JSONUtil.toBean(setting.getSettingValue(), GoodsSetting.class);
                                //缩略图
                                String thumbnail = FileUtil.getUrl(ossPath, goodsSetting.getAbbreviationPictureWidth(), goodsSetting.getAbbreviationPictureHeight());
                                //小图
                                String small = FileUtil.getUrl(ossPath, goodsSetting.getSmallPictureWidth(), goodsSetting.getSmallPictureHeight());
                                //赋值
                                item.setBig(ossPath);
                                item.setSmall(small);
                                item.setThumbnail(thumbnail);
                                mm.put("url",ossPath);
                                imgList.set(0,mm);
                                specMap.put(GoodsSku.IMAGES_KEY,imgList);
                                item.setSpecs(JSON.toJSONString(specMap));
                                skuUpdateList.add(item);
                            }
                        }

                    }
                }
            });
            if(skuUpdateList.size()>0){
                goodsClient.updateGoodsSkuImages(skuUpdateList);
            }

        }
    }




    @Override
    public void transferImageToOss(GoodsSku goodsSku) {
        String keystr = "https://feiyu-lshop";
        Map<String,Object> specMap  = JSON.parseObject(goodsSku.getSpecs(),Map.class);
        if(specMap.containsKey(GoodsSku.IMAGES_KEY)){
            List<Map<String,String>> imgList = (List<Map<String, String>>)specMap.get(GoodsSku.IMAGES_KEY);
            if(!imgList.isEmpty()){
                Map<String,String> mm = imgList.get(0);
                String url = mm.get("url");
                if(!url.contains(keystr)){
                    String ossPath = uploadClient.upload(url);
                    System.out.println("================sku ori="+url+",to="+ossPath);
                    if(null!=ossPath){
                        Setting setting = settingClient.get(SettingEnum.GOODS_SETTING.name());
                        GoodsSetting goodsSetting = JSONUtil.toBean(setting.getSettingValue(), GoodsSetting.class);
                        //缩略图
                        String thumbnail = FileUtil.getUrl(ossPath, goodsSetting.getAbbreviationPictureWidth(), goodsSetting.getAbbreviationPictureHeight());
                        //小图
                        String small = FileUtil.getUrl(ossPath, goodsSetting.getSmallPictureWidth(), goodsSetting.getSmallPictureHeight());
                        //赋值
                        goodsSku.setBig(ossPath);
                        goodsSku.setSmall(small);
                        goodsSku.setThumbnail(thumbnail);
                        mm.put("url",ossPath);
                        imgList.set(0,mm);
                        specMap.put(GoodsSku.IMAGES_KEY,imgList);
                        goodsSku.setSpecs(JSON.toJSONString(specMap));
                    }
                }

            }
        }
        if(null!=goodsSku.getOriginal()){
            System.out.println("================sku ori="+goodsSku.getOriginal());
            if(!goodsSku.getOriginal().contains(keystr)){
                String ossPath = uploadClient.upload(goodsSku.getOriginal());
                System.out.println("================sku to="+ossPath);
                if(null!=ossPath){
                    Setting setting = settingClient.get(SettingEnum.GOODS_SETTING.name());
                    GoodsSetting goodsSetting = JSONUtil.toBean(setting.getSettingValue(), GoodsSetting.class);
                    //缩略图
                    String thumbnail = FileUtil.getUrl(ossPath, goodsSetting.getAbbreviationPictureWidth(), goodsSetting.getAbbreviationPictureHeight());
                    //小图
                    String small = FileUtil.getUrl(ossPath, goodsSetting.getSmallPictureWidth(), goodsSetting.getSmallPictureHeight());
                    //赋值
                    goodsSku.setOriginal(ossPath);
                    goodsSku.setBig(ossPath);
                    goodsSku.setSmall(small);
                    goodsSku.setThumbnail(thumbnail);
                }
            }
        }
        goodsClient.updateGoodsSku(goodsSku);

    }



    private  List<String> getUrls(String str) {
        Pattern pattern = Pattern.compile("(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
//        String a = "[{\"element\":\"lbtEl\",\"name\":\"轮播图\",\"icon\":\"el-icon-data-board\",\"attribute\":{\"marginTop\":0,\"marginBottom\":0,\"marginLeft\":0,\"marginRight\":0,\"imageList\":[{\"name\":\"image\",\"url\":\"https://paiqi-1.oss-cn-beijing.aliyuncs.com/paiqi/20220512/d5b886c221f64c15ae96632d41ca1bda.jpg\",\"height\":800,\"width\":750,\"uid\":1652326171322,\"status\":\"success\"},{\"name\":\"image\",\"url\":\"https://paiqi-1.oss-cn-beijing.aliyuncs.com/paiqi/20220512/5e82ceaad5444b1d8f315fce840d9035.jpg\",\"height\":800,\"width\":750,\"uid\":1652326180600,\"status\":\"success\"}],\"Time\":3}},{\"element\":\"imageEl\",\"name\":\"图片\",\"icon\":\"el-icon-picture-outline\",\"attribute\":{\"marginTop\":0,\"marginBottom\":0,\"marginLeft\":0,\"marginRight\":0,\"image\":\"https://paiqi-1.oss-cn-beijing.aliyuncs.com/paiqi/20220512/c40ec60a89ce4c48b6972ac43e470c09.jpg\"}},{\"element\":\"videoEl\",\"name\":\"视频\",\"icon\":\"el-icon-video-camera\",\"attribute\":{\"marginTop\":0,\"marginBottom\":0,\"marginLeft\":0,\"marginRight\":0,\"video\":\"https://paiqi-1.oss-cn-beijing.aliyuncs.com/paiqi/20220512/fbe7fc1335bd4dc7b8bca6c2693b5200.mp4\"}},{\"element\":\"textEl\",\"name\":\"文本\",\"icon\":\"el-icon-edit\",\"attribute\":{\"marginTop\":0,\"marginBottom\":0,\"marginLeft\":0,\"marginRight\":0,\"content\":\"内容\"}},{\"element\":\"linkEl\",\"name\":\"分割线\",\"icon\":\"el-icon-tickets\",\"attribute\":{\"marginTop\":25,\"marginBottom\":25,\"marginLeft\":0,\"marginRight\":0,\"borderStyle\":\"solid\",\"borderWidth\":1,\"borderColor\":\"#000\",\"width\":100}},{\"element\":\"phoneEl\",\"name\":\"电话\",\"icon\":\"el-icon-phone-outline\",\"attribute\":{\"fontSize\":14,\"color\":\"#fff\",\"background\":\"#07C160\",\"content\":\"拨打电话\",\"btnWeight\":\"normal\",\"phone\":\"13332333333\"}},{\"element\":\"shopCardEl\",\"name\":\"商家名片\",\"icon\":\"el-icon-wallet\",\"attribute\":{\"name\":\"测试地址\",\"address\":\"四川国际大厦\",\"phone\":\"14444444444\",\"lat\":30.66068,\"lng\":104.071519,\"marginTop\":0,\"marginBottom\":0,\"marginLeft\":80,\"marginRight\":0}},{\"element\":\"noticeEl\",\"name\":\"公告\",\"icon\":\"el-icon-takeaway-box\",\"attribute\":{\"direction\":\"left\",\"scrollamount\":3,\"marginTop\":0,\"marginBottom\":0,\"marginLeft\":0,\"marginRight\":0,\"color\":\"#000\",\"content\":\"公告的格式变化就是不回家的说不定还巴适得很不合适的\"}}]";
        Matcher matcher = pattern.matcher(str);
        List<String> urlArr = new ArrayList<>();
        while (matcher.find()) {
            urlArr.add(matcher.group());
        }
        return urlArr;
    }
}
